<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;

class Report extends Model
{
    use HasFactory;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'user_id',
        'reportable_type',
        'reportable_id',
        'reason',
        'description',
        'status',
        'admin_id',
        'admin_comment',
        'processed_at',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'processed_at' => 'datetime',
    ];

    /**
     * 举报者
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    /**
     * 处理管理员
     */
    public function admin(): BelongsTo
    {
        return $this->belongsTo(User::class, 'admin_id');
    }

    /**
     * 被举报的对象（多态关联）
     */
    public function reportable(): MorphTo
    {
        return $this->morphTo();
    }

    /**
     * 判断是否已处理
     */
    public function isProcessed(): bool
    {
        return in_array($this->status, ['resolved', 'rejected']);
    }

    /**
     * 判断是否待处理
     */
    public function isPending(): bool
    {
        return $this->status === 'pending';
    }
}
